package gateway.internal.config.yaml;

import gateway.config.FilterConfig;
import gateway.config.RouteConfig;
import gateway.internal.config.impl.DefaultConnectorConfig;
import gateway.internal.config.impl.DefaultFilterConfig;
import gateway.internal.config.impl.DefaultInboundConfig;
import gateway.internal.config.impl.DefaultOutboundConfig;
import gateway.internal.config.impl.DefaultRouteConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-15
 */
public class YamlRouteConfig
{
	private String id;
	private int order;
	private DefaultConnectorConfig connector;
	private DefaultInboundConfig inbound;
	private List<DefaultFilterConfig> filters;
	private DefaultOutboundConfig outbound;
	private Map<String, String> args;

	public YamlRouteConfig()
	{
	}

	public RouteConfig toConfig()
	{
		DefaultRouteConfig config = new DefaultRouteConfig();
		config.setId(id);
		config.setOrder(order);
		config.setConnector(connector);
		config.setInbound(inbound);
		config.setOutbound(outbound);
		List<FilterConfig> list = new ArrayList<>();
		config.setFilters(list);
		if (filters != null && !filters.isEmpty())
		{
			for (DefaultFilterConfig filter : filters)
			{
				list.add(filter);
			}
		}
		config.setArgs(args == null ? Map.of() : Map.copyOf(args));
		return config;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public int getOrder()
	{
		return order;
	}

	public void setOrder(int order)
	{
		this.order = order;
	}

	public DefaultConnectorConfig getConnector()
	{
		return connector;
	}

	public void setConnector(DefaultConnectorConfig connector)
	{
		this.connector = connector;
	}

	public DefaultInboundConfig getInbound()
	{
		return inbound;
	}

	public void setInbound(DefaultInboundConfig inbound)
	{
		this.inbound = inbound;
	}

	public List<DefaultFilterConfig> getFilters()
	{
		return filters;
	}

	public void setFilters(List<DefaultFilterConfig> filters)
	{
		this.filters = filters;
	}

	public DefaultOutboundConfig getOutbound()
	{
		return outbound;
	}

	public void setOutbound(DefaultOutboundConfig outbound)
	{
		this.outbound = outbound;
	}

	public Map<String, String> getArgs()
	{
		return args;
	}

	public void setArgs(Map<String, String> args)
	{
		this.args = args;
	}
}
